From: kaf24@scramble.cl.cam.ac.uk Date: Thu, 6 May 2004 10:26:17 +0000 (+0000) Subject: bitkeeper revision 1.891.1.1 (409a12c9_7u5WpEokOglsC5WPWr5gQ) X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~18221^2~6 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=9687f61b49c7864fe60468036ec6da8620e36426;p=xen.git bitkeeper revision 1.891.1.1 (409a12c9_7u5WpEokOglsC5WPWr5gQ) Fix compile warnings. --- diff --git a/tools/xc/py/Xc.c b/tools/xc/py/Xc.c index 929e9f3104..974ad994b7 100644 --- a/tools/xc/py/Xc.c +++ b/tools/xc/py/Xc.c @@ -13,6 +13,7 @@ #include #include #include +#include /* Needed for Python versions earlier than 2.3. */ #ifndef PyMODINIT_FUNC @@ -199,15 +200,16 @@ static PyObject *pyxc_linux_save(PyObject *self, &dom, &state_file, &progress) ) return NULL; - if (progress) flags |= XCFLAGS_VERBOSE; + if ( progress ) + flags |= XCFLAGS_VERBOSE; - if (strncmp(state_file,"tcp:", strlen("tcp:")) == 0) + if ( strncmp(state_file,"tcp:", strlen("tcp:")) == 0 ) { #define max_namelen 64 char server[max_namelen]; char *port_s; int port=777; - int sd = 0; + int sd = -1; struct hostent *h; struct sockaddr_in s; int sockbufsize; @@ -215,19 +217,18 @@ static PyObject *pyxc_linux_save(PyObject *self, int writerfn(void *fd, const void *buf, size_t count) { int tot = 0, rc; - do - { + do { rc = write( (int) fd, ((char*)buf)+tot, count-tot ); - if (rc<0) { perror("WRITE"); return rc; }; + if ( rc < 0 ) { perror("WRITE"); return rc; }; tot += rc; } - while(toth_addr, &(s.sin_addr.s_addr), h->h_length); s.sin_port = htons(port); - if( connect(sd, (struct sockaddr *) &s, sizeof(s)) ) + if ( connect(sd, (struct sockaddr *) &s, sizeof(s)) ) goto serr; sockbufsize=128*1024; - if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, sizeof sockbufsize) < 0) - { + if ( setsockopt(sd, SOL_SOCKET, SO_SNDBUF, + &sockbufsize, sizeof sockbufsize) < 0 ) goto serr; - } - if ( xc_linux_save(xc->xc_handle, dom, flags, writerfn, (void*)sd) == 0 ) + if ( xc_linux_save(xc->xc_handle, dom, flags, + writerfn, (void*)sd) == 0 ) { close(sd); Py_INCREF(zero); return zero; } - serr: - + serr: PyErr_SetFromErrno(xc_error); - if(sd)close(sd); + if ( sd >= 0 ) close(sd); return NULL; } else { - int fd; - gzFile gfd; + int fd = -1; + gzFile gfd = NULL; int writerfn(void *fd, const void *buf, size_t count) { @@ -310,10 +311,11 @@ static PyObject *pyxc_linux_save(PyObject *self, err: PyErr_SetFromErrno(xc_error); - if(gfd)gzclose(gfd); - if(fd)close(fd); + if ( gfd != NULL ) + gzclose(gfd); + if ( fd >= 0 ) + close(fd); unlink(state_file); - return NULL; } @@ -336,15 +338,16 @@ static PyObject *pyxc_linux_restore(PyObject *self, &dom, &state_file, &progress) ) return NULL; - if (progress) flags |= XCFLAGS_VERBOSE; + if ( progress ) + flags |= XCFLAGS_VERBOSE; - if (strncmp(state_file,"tcp:", strlen("tcp:")) == 0) + if ( strncmp(state_file,"tcp:", strlen("tcp:")) == 0 ) { #define max_namelen 64 char server[max_namelen]; char *port_s; int port=777; - int ld = 0, sd = 0; + int ld = -1, sd = -1; struct hostent *h; struct sockaddr_in s, d, p; socklen_t dlen, plen; @@ -356,20 +359,16 @@ static PyObject *pyxc_linux_restore(PyObject *self, int rc, tot = 0; do { rc = read( (int) fd, ((char*)buf)+tot, count-tot ); - if (rc<0) - { - perror("READ"); - return rc; - } + if ( rc < 0 ) { perror("READ"); return rc; } tot += rc; - } while( toth_addr, &(s.sin_addr.s_addr), h->h_length); s.sin_addr.s_addr = htonl(INADDR_ANY); s.sin_port = htons(port); - if (setsockopt(ld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) + if ( setsockopt(ld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0 ) goto serr; - if( bind(ld, (struct sockaddr *) &s, sizeof(s)) ) + if ( bind(ld, (struct sockaddr *) &s, sizeof(s)) ) goto serr; - if( listen(ld, 1) ) + if ( listen(ld, 1) ) goto serr; dlen=sizeof(struct sockaddr); - if( (sd = accept(ld, (struct sockaddr *) &d, &dlen )) < 0 ) + if ( (sd = accept(ld, (struct sockaddr *) &d, &dlen )) < 0 ) goto serr; plen = sizeof(p); - if (getpeername(sd, (struct sockaddr_in *) &p, - &plen) < 0) { + if ( getpeername(sd, (struct sockaddr_in *) &p, + &plen) < 0 ) goto serr; - } - printf("Accepted connection from %s\n", - inet_ntoa(p.sin_addr)); + printf("Accepted connection from %s\n", inet_ntoa(p.sin_addr)); sockbufsize=128*1024; - if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, sizeof sockbufsize) < 0) - { + if ( setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, + sizeof sockbufsize) < 0 ) goto serr; - } - if ( xc_linux_restore(xc->xc_handle, dom, flags, readerfn, (void*)sd, &dom) == 0 ) + if ( xc_linux_restore(xc->xc_handle, dom, flags, + readerfn, (void*)sd, &dom) == 0 ) { close(sd); Py_INCREF(zero); return zero; } - serr: - + serr: PyErr_SetFromErrno(xc_error); - if(ld)close(ld); - if(sd)close(sd); + if ( ld >= 0 ) close(ld); + if ( sd >= 0 ) close(sd); return NULL; } else { - int fd; - gzFile gfd; + int fd = -1; + gzFile gfd = NULL; int readerfn(void *fd, void *buf, size_t count) { @@ -441,7 +437,7 @@ static PyObject *pyxc_linux_restore(PyObject *self, return ! (rc == count); } - if (strncmp(state_file,"file:",strlen("file:")) == 0) + if ( strncmp(state_file,"file:",strlen("file:")) == 0 ) state_file += strlen("file:"); if ( (fd = open(state_file, O_RDONLY)) == -1 ) @@ -463,7 +459,8 @@ static PyObject *pyxc_linux_restore(PyObject *self, } - if ( xc_linux_restore(xc->xc_handle, dom, flags, readerfn, gfd, &dom) == 0 ) + if ( xc_linux_restore(xc->xc_handle, dom, flags, + readerfn, gfd, &dom) == 0 ) { gzclose(gfd); close(fd); @@ -474,8 +471,8 @@ static PyObject *pyxc_linux_restore(PyObject *self, err: PyErr_SetFromErrno(xc_error); - if(gfd)gzclose(gfd); - if(fd)close(fd); + if ( gfd != NULL ) gzclose(gfd); + if ( fd >= 0 ) close(fd); return NULL; }